package models;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import com.google.gson.annotations.Expose;

import play.data.validation.MaxSize;
import play.db.jpa.GenericModel;
import play.db.jpa.Model;

/**
 * la classe des items de tourisme
 * @author islam
 *
 */

@Entity
public class ToursicItem extends Model{
	
	@Expose
	public String name;
	@Lob
    @MaxSize(10000)
	@Expose
	public String description;
	@Expose
	public int prix;
	
	 @ManyToOne
	 @Expose
	 public City city;
	 
	 @Expose
	 @OneToOne(mappedBy="toursicItem", cascade=CascadeType.ALL)
	 public Coords coords;
	 
	 @Expose
	 @ManyToOne
	 public Type type;	
	 
	 public ToursicItem() {
		 
	 }
	 
	public ToursicItem(String name, String description, int prix, City city,
			String email, String address, String website, String longitude, 
			String latitude, Type type) {
		this.name = name;
		this.description = description;
		this.prix = prix;
		this.city = city;
		this.coords = new Coords(email, address, website, longitude, latitude, this);
		this.type = type;
	}
	
	public ToursicItem addTourItem(String name, String description, int prix, long cityId,
			String email, String address, String website, String longitude, 
			String latitude, long typeId) {
		Type type = Type.findById(typeId);
		City city = City.findById(cityId);
		ToursicItem tourItem = new ToursicItem(name, description, prix, city, email, address, website, longitude, latitude, type);
		return tourItem;
	}
	
	@Override
	public String toString() {
	    return name;
	}

}
